﻿
@{
    Layout = null;
}
<div ng-controller="CouponController">
    <!-- 优惠券轮播图 -->
    <div>
        <div>
            <carousel interval="myInterval">
                <slide ng-repeat="slide in slides" active="slide.active">
                    <a href="{{slide.url}}"><img ng-src="{{slide.image}}" style="margin: auto;" alt="" /></a>
                </slide>
            </carousel>
        </div>
    </div>
    <!--end 优惠券轮播图 -->
    <!-- 优惠券列表 -->
    <div class="flayout_b_mainBox">
        <!-- 可用 -->
        <div class="flayout_b_mainEachTab">
            <div class="flayout_b_eachRow blue flayout_c_eachRow" ng-repeat="item in CouponList">
                <div class="rightbox leftpart">
                    <div class="imgBox">
                        <img src="{{item.Category>0?ImgHostUrl+item.PicUrl:'/Content/images/logo.jpg'}}">
                    </div>
                    <div class="lrpart">
                        <div class="lrpart_tp"><span class="span1">¥</span><span class="span2">{{item.Amount}}</span><label ng-show="item.Consumption>0">满{{item.Consumption}}使用</label></div>
                        <p class="lrpart_bm">{{item.CouponName}}</p>
                    </div>
                </div>
                <div class="leftbox rightpart">
                    <div class="progressMain">
                        <div class="txt" ng-show="item.TotalNum>0">已领{{item.ReceiveRate}}%</div>
                        @*<div class="progres_all" ng-show="item.TotalNum>0"><p></p></div>*@
                    </div>
                    <input type="button" value="{{item.ReceiveRate>=100?'已领完':'立即领券'}}" class="receiveBtn" ng-click="receiveCoupon(item.Id,item.ReceiveRate)">
                </div>
                <div class="clear"></div>
            </div>

        </div>
    </div>
    <!-- 优惠券列表 -->
</div>
<script>
    App.controller('CouponController', [
        '$scope', '$http', '$rootScope', '$stateParams', '$state', '$filter', '$timeout',
    function ($scope, $http, $rootScope, $stateParams, $state, $filter, $timeout) {
        $scope.CarouselList = [];

        //数据初始化
        $http.post("/Coupon/GetCarouselList", {}).then(function (response) {
            if (response.data.isSuccess) {
                
                $scope.CarouselList = response.data.data;
            }
            // 设置轮播图图片间隔
            $scope.myInterval = 5000;
            // 轮播图数据初始化
            var slides = $scope.slides = [];
            // 添加轮播图源
            if ($scope.CarouselList.length > 0) {
                angular.forEach($scope.CarouselList, function (img) {
                    slides.push({ image: $rootScope.ImgHostUrl + img.ImgUrl, url: img.LinkUrl });
                });
            }

            var tt = function () {
                $rootScope.WxShare($rootScope.pageTitle(), '优品三悦', location.href, $rootScope.LogoUrl);
            }

            setTimeout(tt, 1000)

        });

        var getCouponList = function ()
        {
            $http.post("/Coupon/GetCouponList", {}).then(function (response) {
                if (response.data.isSuccess) {
                    console.log(response.data.data);
                    $scope.CouponList = response.data.data;
                }

            });
        }

        getCouponList();

        $scope.receiveCoupon = function (id,num)
        {
            if (num >= 100)
            {
                return;
            }

            layer.load(2);

            $http.post("/Coupon/ReceiveCoupon", { couponId: id }).then(function (response) {
                layer.closeAll('loading');
                if (response.data.isSuccess) {
                    layer.msg("领取成功");
                    getCouponList();
                }
                else {
                    layer.msg(response.data.msg);
                }

            });
        }


    }]);
</script>
